<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1、trim()方法小技巧
        // let str = "    star    ";
        // console.log(str.trim()); 

        // 2、使用正则表达式删除开头和结尾的空白

        let hello = "   Hello, World!  ";
        let reg = /(^\s*|\s*$)/g; // 表示以空格开头或以空格结尾 
        let result = hello.replace(reg, ""); // 巧妙运用字符串的replace方法
        console.log(result);
    </script>
</body>

</html>